{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.common import PayReceive, Currency\n",
    "from gs_quant.instrument import EqOption\n",
    "from gs_quant.session import Environment, GsSession\n",
    "from gs_quant.risk import MarketDataShockBasedScenario, MarketDataPattern, MarketDataShock, MarketDataShockType\n",
    "from gs_quant.risk import EqDelta, EqVega, EqSpot, Price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics',))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "o = EqOption('.SPX')\n",
    "o.resolve()\n",
    "p = o.price()\n",
    "d1 = o.calc(EqDelta)\n",
    "print(f'Base price: {p:,.2f}')\n",
    "print(f'Equity Delta: {d1:,.2f}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# shock equity spot up and down\n",
    "with MarketDataShockBasedScenario(shocks={MarketDataPattern(mkt_type='Eq', mkt_class='Spot', mkt_quoting_style='PropSpread'): MarketDataShock(MarketDataShockType.Override, .005)}):\n",
    "    price_up = o.price()\n",
    "with MarketDataShockBasedScenario(shocks={MarketDataPattern(mkt_type='Eq', mkt_class='Spot', mkt_quoting_style='PropSpread'): MarketDataShock(MarketDataShockType.Override, -.005)}):\n",
    "    price_down = o.price()\n",
    "d2 = (price_up - price_down) / .01\n",
    "\n",
    "print(f'Equity Delta via shocking: {d2:,.2f}')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
